package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper extends BaseMapper<Dish> {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Page<DishVO> pageQuery(DishPageQueryDTO dto);

    @Select("select d.*,c.name as categoryName from dish  d left outer join category c on d.category_id = c.id where d.id=#{id}")
    Dish getDish(Integer id);

    @Select("update setmeal set status = 0 where id in (select setmeal_id from setmeal_dish where dish_id = #{id})")
    void disableSetmeal(Long id);

    @Select("select count(*) from dish where id in (select dish_id from  setmeal_dish where setmeal_id=#{id} ) and status = 0")
    Integer getDishCountBySetmealId(Long id);

    @Select("select d.*,c.name as categoryName from dish  d left outer join category c on d.category_id = c.id where d.status=1 and d.category_id = #{categoryId}")
    List<Dish> getDishByCategoryId(Long categoryId);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
